package objects
{
    import flash.geom.Vector3D;

    public class Object3DUtil
    {
        public static function lineSegIntersectPlane(l0 : Vector3D, l1 : Vector3D, p : Vector3D, n : Vector3D) : Vector3D
        {
            var d : Number;
            var _n : Number;
            var si : Number;
            
            var lineDir : Vector3D = l1.subtract(l0);
            var planeDir : Vector3D = l0.subtract(p);
            
            d = n.dotProduct(lineDir);
            _n = n.dotProduct(planeDir);
            
            if (Math.abs(d) < 0.0001 || Math.abs(_n) < 0.0001)
            {
                return null;
            }
            
            si = _n / d;
            
            return new Vector3D(l0.x - si * lineDir.x, l0.y - si * lineDir.y, l0.z - si * lineDir.z);
        }
    }
}